package edu.vt.ece3574.ninjatag;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;

public class NinjaTagActivity extends Activity /*implements OnClickListener*/{ //Why does the activity implement OnClickListener? -Chris
	
	private Button loginButton;
	private Button settingsButton;
	private EditText initUserName;
	private EditText initPassword;
	private Facebook facebook = new Facebook("208547072576022");
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        loginButton = (Button)findViewById(R.id.buttonLogin);
        loginButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
            	setContentView(R.layout.loggingin);
            	final TextView logintext = (TextView) findViewById(R.id.logintext);
				facebook.authorize(NinjaTagActivity.this, new DialogListener() {

					@Override
					public void onFacebookError(FacebookError arg0) {
		            	logintext.setText("There was a Facebook error.");
						
					}
					
					@Override
					public void onError(DialogError arg0) {
		            	logintext.setText("There was an error.");
						
					}
					
					@Override
					public void onComplete(Bundle arg0) {
		            	logintext.setText("You have successfully logged in.");
						
					}
					
					@Override
					public void onCancel() {
		            	logintext.setText("The logging in routine was canceled.");
						
					}
				});
				
			}
		});
        settingsButton = (Button)findViewById(R.id.buttonSettings);
    }
    
    //when login button is pressed -Craig
    //Nice, except I don't know how to insert strings/EditTexts into the Facebook Authentification process, so I have to ignore it. -Chris
    /*
    public void loginClick(View view){
    	
    	//getting username and password
    	EditText userNameEditText =(EditText)findViewById(R.id.userName);
    	EditText userPassEditText =(EditText)findViewById(R.id.userPassword);
    	
    	//assigning username / password to string variables
    	String loginName = userNameEditText.getText().toString();
    	String loginPass = userPassEditText.getText().toString();
    	
    	if( checkLogin(loginName, loginPass) ){
        	//* Temporary- show a successful login * /
        	((TextView)findViewById(R.id.showUser)).setText("login successful");
        	((TextView)findViewById(R.id.showUser)).setVisibility(View.VISIBLE);
        }
        else showLoginError();
    }//*/

    //authenticate username and password -temporary until integrated with facebook
    /*
    private boolean checkLogin(String name, String pass){
    	
    	((TextView)findViewById(R.id.showUser)).setText(name);
    	((TextView)findViewById(R.id.showUser)).setVisibility(View.VISIBLE);
    	
    	if(name.equalsIgnoreCase("craig") && pass.equalsIgnoreCase("pass") ) return true;
    	else return false;

    }//*/
    
    //display message if username or password is incorrect -Craig
    //Sorry, I ignored this temporarily. I'll get everything proper as soon as I figure out why Facebook hates me. -Chris
	/*
	private void showLoginError(){
		((TextView)findViewById(R.id.showUser)).setText("login failed");
    	((TextView)findViewById(R.id.showUser)).setVisibility(View.VISIBLE);
	}//*/

	//if settings button is pressed
	public void settingsClick(View view){
		((TextView)findViewById(R.id.settingstext)).setVisibility(View.VISIBLE);
		
	}
	
	
	//not sure what this is, but apparently it's needed -Craig
	//This is only needed because you extended implemented OnClickListener, which wasn't necessary. I'm commenting it out. -Chris
	/*
	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		
	}*/
}

